package com.petecat.interchan.system.companyempl.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.petecat.interchan.core.constans.Global;
import com.petecat.interchan.core.controller.BaseController;
import com.petecat.interchan.protocol.GlobalHeader;
import com.petecat.interchan.protocol.Result;
import com.petecat.interchan.protocol.data.PageVO;
import com.petecat.interchan.protocol.sso.company.dto.SysCompanyAddDTO;
import com.petecat.interchan.protocol.sso.company.dto.SysCompanyUpdDTO;
import com.petecat.interchan.protocol.sso.companyempl.dto.BsSmsAddDTO;
import com.petecat.interchan.protocol.sso.companyempl.dto.BsSmsQryDTO;
import com.petecat.interchan.protocol.sso.companyempl.dto.BsSmsUpdDTO;
import com.petecat.interchan.protocol.sso.companyempl.vo.BsSmsQryVO;
import com.petecat.interchan.system.companyempl.service.ICompanyEmplService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@Api("公司员工信息管理")
@RequestMapping("/system/companyempl")
public class CompanyEmplController extends BaseController{

	@Autowired
	private ICompanyEmplService companyEmplService;
	
	@SuppressWarnings("unchecked")
	@ApiOperation("分页查询公司联系人信息")
	@GetMapping("/queryCompanyEmplByPage")
	public Result<PageVO<BsSmsQryVO>> queryCompanyEmplByPage(@ModelAttribute BsSmsQryDTO bsSmsQryDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		bsSmsQryDTO.setUserId(userInfo.getUserId());
		PageVO<BsSmsQryVO> pageVO = companyEmplService.queryCompanyEmplByPage(bsSmsQryDTO);
		return (Result<PageVO<BsSmsQryVO>>) Result.ok(pageVO);
	}
	
	
	@SuppressWarnings("unchecked")
	@ApiOperation("通过UserId获取用户list")
	@GetMapping("/queryCompanyEmplListByUserId")
	public Result<BsSmsQryVO> queryCompanyEmplListByUserId(@ModelAttribute BsSmsQryDTO bsSmsQryDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		bsSmsQryDTO.setUserId(userInfo.getUserId());
		BsSmsQryVO pageVO = companyEmplService.queryCompanyEmplListByUserId(bsSmsQryDTO);
		return (Result<BsSmsQryVO>) Result.ok(pageVO);
	}
	


	@ApiOperation(value = "新增公司联系人基本信息", notes = "新增")
	@PostMapping(value = "/saveCompanyEmpl")
	public Result<?> saveCompanyEmpl(@RequestBody BsSmsAddDTO bsSmsAddDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		companyEmplService.saveCompanyEmpl(bsSmsAddDTO, userInfo.getUserId());
		return Result.ok();
	}

	@ApiOperation("删除公司联系人基本信息")
	@DeleteMapping("/removeCompanyEmplById")
	public Result<?> removeCompanyEmplById(@RequestParam String companyEmplId,@RequestParam String state,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		companyEmplService.removeCompanyEmplById(companyEmplId,state);
		return Result.ok();
	}

	@ApiOperation("修改公司联系人基本信息")
	@PutMapping("/modifyCompanyEmplById")
	public Result<?> modifyCompanyEmplById(@RequestBody BsSmsUpdDTO bsSmsUpdDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		companyEmplService.modifyCompanyById(bsSmsUpdDTO, userInfo.getUserId());
		return Result.ok();
	}

}
